//
//  DurationViewController.m
//  fugitive
//
//  Created by Eugene Bistolas on 5/31/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "DurationViewController.h"


@implementation DurationViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (IBAction) hoursButtons:(UIButton*) sender {   
   if (sender.tag == 1) {
      if ([hoursLabel.text intValue] == 9) {
         hoursLabel.text = @"0"; 
      }
      else {
         hoursLabel.text = [NSString stringWithFormat:@"%d", [hoursLabel.text intValue] + 1]; 
      }
   }
   else if (sender.tag == 2) {
      if ([hoursLabel.text intValue] == 0) {
         hoursLabel.text = @"9"; 
      }
      else {
         hoursLabel.text = [NSString stringWithFormat:@"%d", [hoursLabel.text intValue] - 1];
      }
   }
    
}

- (IBAction) minutesButtons:(UIButton *) sender {
   if (sender.tag == 1) {
      if ([minutesLabel.text intValue] == 45) {
         minutesLabel.text = @"00"; 
      }
      else {
         minutesLabel.text = [NSString stringWithFormat:@"%d", [minutesLabel.text intValue] + 15]; 

      }
   }
   if (sender.tag == 2) {
      if ([minutesLabel.text intValue] == 0) {
         minutesLabel.text = @"45"; 
      }
      else {
         minutesLabel.text = [NSString stringWithFormat:@"%d", [minutesLabel.text intValue] - 15];
      }
   }
}

- (IBAction) powerupsButtons:(UIButton *) sender {
   if (sender.tag == 1) {
      if ([powerupsLabel.text intValue] == 9) {
         powerupsLabel.text = @"0"; 
      }
      else {
         powerupsLabel.text = [NSString stringWithFormat:@"%d", [powerupsLabel.text intValue] + 1]; 
      }
   }
   else if (sender.tag == 2) {
      if ([powerupsLabel.text intValue] == 0) {
         powerupsLabel.text = @"9"; 
      }
      else {
         powerupsLabel.text = [NSString stringWithFormat:@"%d", [powerupsLabel.text intValue] - 1];
      }
   }
}

- (IBAction) navButtons:(UIButton *)sender {
   if (sender.tag == 1) {
      [self.navigationController popToRootViewControllerAnimated:YES]; 
   }
}

- (id) initWithStartTarget:(CLLocationCoordinate2D) start endTarget: (CLLocationCoordinate2D) end {
   self = [super init]; 
   if (self) {
      startLoc = start;
      stopLoc = end; 
      
   }
   
   return self; 
}

- (void)dealloc
{
   [durationHours release];
   [durationMinutes release];
   [hoursUp release];
   [hoursDown release];
   [minutesUp release];
   [minutesDown release];
   [powerupsUp release];
   [powerupsDown release];
   [hoursLabel release];
   [minutesLabel release];
   [powerupsLabel release];
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
   hoursLabel.text = @"0"; 
   minutesLabel.text = @"00"; 
   powerupsLabel.text = @"0"; 
}

- (void)viewDidUnload
{
   [durationHours release];
   durationHours = nil;
   [durationMinutes release];
   durationMinutes = nil;
   [hoursUp release];
   hoursUp = nil;
   [hoursDown release];
   hoursDown = nil;
   [minutesUp release];
   minutesUp = nil;
   [minutesDown release];
   minutesDown = nil;
   [powerupsUp release];
   powerupsUp = nil;
   [powerupsDown release];
   powerupsDown = nil;
   [hoursLabel release];
   hoursLabel = nil;
   [minutesLabel release];
   minutesLabel = nil;
   [powerupsLabel release];
   powerupsLabel = nil;
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
